#!/bin/bash
#decsription install zookeeper
SOFTDIR=/usr/local/src
ZKVER=3.4.9
DATADIR=/opt/data/zookeeper
IP=$(ifconfig eth0|grep inet|grep -v "inet6"|awk '{print $2}')
NUM=01
CLIENTPORT=2181
#create zk datadir and touch NUM to myid
[ ! -d $DATADIR ] && mkdir -p $DATADIR
echo $NUM > ${DATADIR}/myid

#install java environment
cd $SOFTDIR && [ ! -f jdk-8u131-linux-x64.rpm ] && wget http://soft.51yuki.cn/jdk-8u131-linux-x64.rpm && yum -y localinstall jdk-8u131-linux-x64.rpm
#install zookeeper
cd $SOFTDIR && [ ! -f zookeeper-${ZKVER}.tar.gz ] && wget http://soft.51yuki.cn/zookeeper-${ZKVER}.tar.gz
cd /usr/local 
if [ ! -d zookeeper-${ZKVER} ];then
	cd $SOFTDIR && tar xf zookeeper-${ZKVER}.tar.gz -C /usr/local
	ln -s /usr/local/zookeeper-${ZKVER} /usr/local/zookeeper
fi
#configure zookeeper env variables
echo "export PATH=/usr/local/zookeeper/bin:$PATH" > /etc/profile.d/zookeeper.sh
source /etc/profile.d/zookeeper.sh

#configure zookeeper

cd /usr/local/zookeeper/conf
cat >zoo.cfg <<EOF
tickTime=2000
initLimit=10
syncLimit=5
dataDir=$DATADIR
clientPort=$CLIENTPORT
#maxClientCnxns=60
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
EOF

#安装完所有zookeeper节点后，在额外修改zoo.cfg配置文件，添加如
#server.01=distr01:2888:3888
#server.02=distr02:2888:3888
#server.03=distr03:2888:3888
